using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Castle.ActiveRecord;
using NHibernate.Expression;

namespace WOODIFramework.Model
{
    [ActiveRecord("PageItem"), JoinedBase]
    public class PageItem : ActiveRecordBase<PageItem>
    {
        #region Fields

        private Guid _id;
        private string _name;
        private string _displayName;
        private IList _pages;
        private Dictionary<string, string> _boundObjectProperties = new Dictionary<string,string>();
        private string _style;
        private string _dataBoundFieldsFormatString = string.Empty;
        private Dictionary<string, ActiveRecordBase> _boundObjects;
        private Dictionary<string, ActiveRecordBase[]> _boundCollections;
        private int _order;

        #endregion

        #region Properties

        [PrimaryKey(PrimaryKeyType.Guid)]
        public Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }

        [Property("Name", NotNull = false)]
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        [Property]
        public string DisplayName
        {
            get { return _displayName; }
            set { _displayName = value; }
        }

        [HasAndBelongsToMany(typeof(Page),
        Table = "PageItemPage", ColumnKey = "PageItemId", ColumnRef = "PageId", Inverse=true)]
        public IList Pages
        {
            get { return _pages; }
            set { _pages = value; }
        }

        /// <summary>
        /// Fields that can be bound to the page object. 
        /// If no DataBoundFieldFormatString is specified, DataBoundField at position 0 is used
        /// </summary>
        [Property]
        public Dictionary<string, string> DataBoundObjectProperties
        {
            get { return _boundObjectProperties; }
            set { _boundObjectProperties = value; }
        }

        /// <summary>
        /// Format string for the DataBoundField
        /// </summary>
        [Property]
        public string DataBoundFieldsFormatString
        {
            get { return _dataBoundFieldsFormatString; }
            set { _dataBoundFieldsFormatString = value; }
        }

        [Property]
        public string Style
        {
            get { return _style; }
            set { _style = value; }
        }

        public Dictionary<string, ActiveRecordBase> BoundObjects
        {
            get { return _boundObjects; }
            set { _boundObjects = value; }
        }

        public Dictionary<string, ActiveRecordBase[]> BoundCollections
        {
            get { return _boundCollections; }
            set { _boundCollections = value; }
        }

        [Property]
        public int PageItemOrder
        {
            get { return _order; }
            set { _order = value; }
        }

        #endregion

        #region Public Methods

        public virtual string RenderHTML()
        {
            return null;
        }

        #endregion
    }
}
